﻿using System;
using System.Web;

namespace LsTool
{
    /// <summary>
    ///  Cookies
    /// </summary>
    public class CookiesCom
    {
        /// <summary>
        /// 获取Cookies
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string Get(string key)
        {
            var httpCookie = HttpContext.Current.Request.Cookies[key]; 
            return httpCookie?.Value ;
        }

        public static void Set(string key,string value, DateTime dateTime)
        {
            var httpCookie = HttpContext.Current.Request.Cookies[key];
            if (httpCookie==null)
            {
                var hc = new HttpCookie(key);
                hc.Value = value;
                hc.Expires = dateTime;
                HttpContext.Current.Response.Cookies.Add(hc);
            }
            else
            {
                httpCookie.Value = value;
                HttpContext.Current.Response.Cookies.Set(httpCookie);
            }
            
        }
    }
}